import type { IRegisterUser } from '@/views/register/Register.vue'
import type { IUpdatePassword } from '@/views/updatePassword/UpdatePassword.vue'
import type { IUserInfo } from '@/views/updateUserInfo/UpdateUserInfo.vue'
import Http from './axios'
import type { SearchMeetingRoom } from '@/views/meetingRoomManage/index.vue'
import type { SearchBooking } from '@/views/bookingHistory/index.vue'
import type { CreateBooking } from '@/views/meetingRoomManage/CreateBookingModal'

export async function login(username: string, password: string) {
  return await Http.post('/user/login', {
    username,
    password
  })
}

export async function registerCaptcha(email: string) {
  return await Http.get('/user/register-captcha', {
    params: {
      address: email
    }
  })
}
export async function register(params: IRegisterUser) {
  return await Http.post('/user/register', params)
}

export async function updatePasswordCaptcha(email: string) {
  return await Http.get('/user/update_password/captcha', {
    params: {
      address: email
    }
  })
}
export async function updatePassword(data: IUpdatePassword) {
  return await Http.post('/user/update_password', data)
}

export async function getUserInfo() {
  return await Http.get('/user/info')
}

export async function updateUserInfo(data: IUserInfo) {
  return await Http.post('/user/update', data)
}

export async function updateUserInfoCaptcha() {
  return await Http.get('/user/update/captcha')
}

export const meetingRoomList = async (condition: SearchMeetingRoom) => {
  return Http.get('/meeting-room/list', {
    params: {
      ...condition
    }
  })
}

export const deleteMeetingRoom = async (id: number) => {
  return Http.delete(`/meeting-room/${id}`)
}

export const getBookingList = async (condition: SearchBooking) => {
  return await Http.get('/booking/list', {
    params: {
      ...condition
    }
  })
}

export const unbind = async (id: number) => {
  return await Http.get(`/booking/unbind/${id}`)
}

export async function bookingAdd(booking: CreateBooking) {
  return await Http.post('/booking/add', booking)
}

export async function presignedUrl(fileName: string) {
  return Http.get(`/minio/presignedUrl?name=${fileName}`)
}

export async function uploadFile(formData: FormData) {
  return Http.post('/user/upload', formData, {
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}
